package com.tsingteng.cosfun.base;


import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.mvp.view.IView;

/**
 * 描述: 请求网络基类activity
 * 创建人: 肖利
 *时间: 2018/7/30
 * qq: (872179966)
 */
public abstract class BasePresenterActivity<P extends BasePresenter,V extends IView> extends BaseActivity implements IView {
    protected P mPresenter;
    @Override
    protected void initView() {
        //创建presenter
        mPresenter = createPresenter();
        //绑定view
        attachView();
        initData();
    }

    /**
     * 初始化逻辑
     */
    protected abstract void initData();


    private void attachView() {
        if (mPresenter!=null) {
            mPresenter.attachView((V)this);
        }
    }

    protected abstract P createPresenter();

    @Override
    public void showLoading(String msg) {
        showLoadingDialog(msg);
    }

    @Override
    public void hideLoading() {
        hideLoadingDialog();
    }

    @Override
    public void showFail(String msg) {
        showToast(msg);
        hideLoadingDialog();
    }

    @Override
    public void showError() {
        hideLoadingDialog();
    }

    @Override
    public void showEmpty() {
        hideLoadingDialog();
    }




    @Override
    protected void onDestroy() {
        //view置空  取消所有的请求
        if (mPresenter!=null) {
            mPresenter.detachView();
            mPresenter.removeAllDisposable();
        }
        super.onDestroy();
    }
}
